package cn.edu.hunau.pm.common;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

public class ParseBindingResult {
    public static String parse(BindingResult bindingResult) {
        StringBuilder sb=new StringBuilder();
        if (bindingResult!=null && bindingResult.hasErrors()) {
            List<FieldError> fieldErrors = bindingResult.getFieldErrors();

            fieldErrors.forEach(fe -> {
                String errMessage = fe.getDefaultMessage();
                sb.append(errMessage);
                sb.append(";");
            });
            return sb.substring(0,sb.length()-1);
        }
        return null;
    }
}